package com.greyu.ysj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import com.greyu.ysj.config.ResultStatus;
import com.greyu.ysj.entity.CbtBallot;
import com.greyu.ysj.entity.CbtCreateCoinExample;
import com.greyu.ysj.entity.CbtCreateCoin;
import com.greyu.ysj.mapper.CbtCreateCoinMapper;
import com.greyu.ysj.model.ResultModel;
import com.greyu.ysj.service.CbtCreateCoinService;

@Service
@Transactional
public class CbtCreateCoinServiceImpl implements CbtCreateCoinService{
	@Autowired
	private CbtCreateCoinMapper cbtCreateCoinMapper;

	@Override
	public CbtCreateCoin selectCoinInfoBycoinSymbol(String coinSymbol) {
		CbtCreateCoinExample cbtCreateCoinExample = new CbtCreateCoinExample();
        CbtCreateCoinExample.Criteria criteria = cbtCreateCoinExample.createCriteria();
        criteria.andCoinSymbolEqualTo(coinSymbol);
        List<CbtCreateCoin> coinList = this.cbtCreateCoinMapper.selectByExample(cbtCreateCoinExample);

        CbtCreateCoin cbtCreateCoin;
        try {
        	cbtCreateCoin = coinList.get(0);
        } catch (Exception e) {
            return null;
        }
		return cbtCreateCoin;
	}

	 
	@Override
	public List<CbtCreateCoin> selectCoinVotesList() {
		List<CbtCreateCoin> list=cbtCreateCoinMapper.selectCoinVoteList();
		for(CbtCreateCoin coin:list) {
			CbtBallot cbtBallot=coin.getCbtBallot();
			System.out.println("@@@@@@@@@@@"+cbtBallot);
		}
		if(list==null||list.size()<1) {
			return null;
		}
		return list;
	}


	@Override
	public ResultModel save(CbtCreateCoin cbtCreateCoin) {
		try {	
			if ( cbtCreateCoin.getCoinChineseName()==null
					||cbtCreateCoin.getCoinSymbol()==null
	        		) {
	            return ResultModel.error(ResultStatus.DATA_NOT_NULL);
	        }
			//insert
	        this.cbtCreateCoinMapper.insert(cbtCreateCoin);
		} catch (Exception e) {
			return ResultModel.error(ResultStatus.INSERT_ERROR);
		}
	        return ResultModel.ok(cbtCreateCoin);
		}

	
}

